package com.elric.mall.controller;

import com.elric.mall.mapper.ProjectEntityNewDao;
import com.elric.mall.model.ProjectEntityNew;
import com.elric.mall.common.api.CommonResult;
import com.elric.mall.service.SettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 实现功能：
 *
 * @author 作者[Yuxuan.he]
 * @version 1.0.00  2021-09-08 10:50
 */
@RestController
@RequestMapping("/setting")
public class SettingController {

    @Autowired
    ProjectEntityNewDao projectEntityNewDao;

    @Autowired
    SettingService settingService;

    @PostMapping("/insert")
    public CommonResult insert(@RequestBody ProjectEntityNew projectEntityNew) {
        settingService.insertProjectInfo(projectEntityNew);
        return CommonResult.success("ok");
    }

    @GetMapping("/findAll")
    public CommonResult findAll() {
        return CommonResult.success(projectEntityNewDao.findAll());
    }

    @PostMapping("/update")
    public CommonResult update(@RequestBody ProjectEntityNew projectEntityNew) {
        projectEntityNew.setUpdateTime(new Date());
        return CommonResult.success(projectEntityNewDao.updateByFontEnd(projectEntityNew));
    }

    @GetMapping("/other")
    public CommonResult findOther() {
        return CommonResult.success(projectEntityNewDao.findOtherDb());
    }

    @GetMapping("/selectAllProject")
    public CommonResult selectAllProject() {
        return CommonResult.success(projectEntityNewDao.selectAllProject());
    }

    @GetMapping("/init")
    public CommonResult init() {
        settingService.init();
        settingService.formatData();
        return CommonResult.success("ok");
    }
}
